//
//  headerView.swift
//  专业课
//
//  Created by 梓简王 on 2017/8/15.
//  Copyright © 2017年 梓简王. All rights reserved.
//

import Foundation
protocol headerViewDelegate{
    func clickLeftBtn()
    func clickRightBtn()
}

class headerView:UIView {
    var naviHeadView_Image:UIImageView?
    var naviHeadView_BackBtn:UIButton?
    var naviHeadView_RightBtn:UIButton?
    var naviHeadView_Title:UILabel?
    var delegate:headerViewDelegate?
    
    init(frame: CGRect,leftBtnString:String,title:String,rightBtnString:String) {
        super.init(frame: frame)
        //头部背景
        naviHeadView_Image = UIImageView(frame: CGRect(x: 0, y: 0, width: commonVariable.SYSTEM_WIDTH, height: 66))
        naviHeadView_Image?.image = UIImage(named: "naviHead")
        //头部返回按钮
        naviHeadView_BackBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 66, height: 33))
        naviHeadView_BackBtn?.backgroundColor = UIColor.clearColor()
        naviHeadView_BackBtn?.setTitle(leftBtnString, forState: UIControlState.Normal)
        naviHeadView_BackBtn?.titleLabel?.font = UIFont(name: commonVariable.CHINAFONTNAME, size: 14)
        naviHeadView_BackBtn?.setTitleColor(commonVariable.IRONCOLOR, forState: UIControlState.Normal)
        naviHeadView_BackBtn?.center = CGPoint(x: 40, y: 44)
        naviHeadView_BackBtn?.addTarget(self, action: "backBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        //头部标题
        naviHeadView_Title = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 40))
        naviHeadView_Title?.text = title
        naviHeadView_Title?.center = CGPoint(x: commonVariable.SYSTEM_WIDTH/2, y: 44)
        naviHeadView_Title?.font = UIFont(name: commonVariable.CHINAFONTNAME, size: 20)
        naviHeadView_Title?.textAlignment = .Center
        naviHeadView_Title?.textColor = commonVariable.IRONCOLOR
        self.addSubview(self.naviHeadView_Image!)
        self.addSubview(self.naviHeadView_Title!)
        self.addSubview(self.naviHeadView_BackBtn!)
        if(rightBtnString == ""){return}
        //右边的按钮
        naviHeadView_RightBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 66, height: 33))
        naviHeadView_RightBtn?.backgroundColor = UIColor.clearColor()
        naviHeadView_RightBtn?.setTitle(rightBtnString, forState: UIControlState.Normal)
        naviHeadView_RightBtn?.titleLabel?.font = UIFont(name: commonVariable.CHINAFONTNAME, size: 14)
        naviHeadView_RightBtn?.setTitleColor(commonVariable.IRONCOLOR, forState: UIControlState.Normal)
        naviHeadView_RightBtn?.center = CGPoint(x: commonVariable.SYSTEM_WIDTH - 40, y: 44)
        naviHeadView_RightBtn?.addTarget(self, action: "rigthBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        self.addSubview(naviHeadView_RightBtn!)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func backBtnClick(){
        delegate?.clickLeftBtn()
    }
    func rigthBtnClick(){
        delegate?.clickRightBtn()
    }
}